package com.dp.appi.controller;

import com.dp.appi.exception.CommonException;

import com.dp.appi.service.ProblemService;
import com.dp.appi.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Created by chenghao on 2015/9/30.
 */
@Controller
@RequestMapping(value = "/problemControl")
public class ProblemControl {
    private static Logger log = LoggerFactory.getLogger(ProblemControl.class);
    @Autowired
    private ProblemService problemService;

    @RequestMapping(value = "/getProblem",method = RequestMethod.POST)
    public void getProblemList(ModelMap modelMap, @RequestParam Map<String,String> param) {
        try {


            String orgid = param.get("orgid");
            modelMap.addAttribute("problemList",problemService.getProblem(orgid));
            modelMap.addAttribute("problemTermList",problemService.getProblemTerm(orgid));
            modelMap.addAttribute("ProblemPhotoList",problemService.getProblemPhoto(orgid));

        }catch (CommonException c) {
            modelMap.addAllAttributes(SYS.valueOf(c.getMessage()).msgMap());
        }catch (Exception e){
            modelMap.addAllAttributes(SYS.E10002.msgMap());
            log.error(ExceptionUtil.getExceptionAllinformation(e));
        }
    }
    @RequestMapping(value = "/getproblemExist",method = RequestMethod.POST)
    public void getproblemExistList(ModelMap modelMap, @RequestParam Map<String,String> param) {
        try {


            String stateid = param.get("stateid");
            modelMap.addAttribute("problemExistList",problemService.getproblemExist(stateid));
            modelMap.addAttribute("problemExistPhotoList",problemService.getproblemExistPhoto(stateid));

        }catch (CommonException c) {
            modelMap.addAllAttributes(SYS.valueOf(c.getMessage()).msgMap());
        }catch (Exception e){
            modelMap.addAllAttributes(SYS.E10002.msgMap());
            log.error(ExceptionUtil.getExceptionAllinformation(e));
        }
    }

}
